import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { User } from '../entity/User';

@Provide()
export class UserService {
  @InjectEntityModel(User)
  userModel: Repository<User>;

  async createUser(name: string, age: number): Promise<User> {
    const user = new User();
    user.name = name;
    user.age = age;
    return this.userModel.save(user);
  }

  async getUser(id: number): Promise<User> {
    return this.userModel.findOneBy({ id });
  }
}